package cn.edu.buu.hospital.service.impl;

import cn.edu.buu.hospital.entity.Pay;
import cn.edu.buu.hospital.mapper.PayMapper;
import cn.edu.buu.hospital.service.PayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PayServiceImpl implements PayService {

    @Autowired
    private PayMapper payMapper;

    @Override
    public void add(Pay pay) {
        payMapper.insert(pay);
    }

    @Override
    public void removeById(Long payId) {
        payMapper.deleteById(payId);
    }

    @Override
    public void modify(Pay pay) {
        payMapper.update(pay);
    }

    @Override
    public Pay findById(Long payId) {
        return payMapper.selectById(payId);
    }

    @Override
    public List<Pay> findAll() {
        return payMapper.selectAll();
    }

    @Override
    public PageInfo<Pay> find(int pageNum, int pageSize, Pay condition, String payDate) {
        PageHelper.startPage(pageNum, pageSize);
        List<Pay> payList = payMapper.selectByCondition(condition, payDate);
        return new PageInfo<>(payList);
    }
    
    @Override
    public PageInfo<Pay> findByUserId(int pageNum, int pageSize, Long userId, Pay condition, String payDate) {
        PageHelper.startPage(pageNum, pageSize);
        List<Pay> payList = payMapper.selectByUserId(userId);
        return new PageInfo<>(payList);
    }
}